<?php
namespace Common\Model;

/**
 * 微预定推送信息表
 * @modify wenhui 2017-03-16 创建
 * 
 */
Class HotelNewspushModel extends \Think\Model {
	protected $trueTableName = 'bk_hotel_newspush';

	protected function _before_insert(&$data, $options) {

    }

	 /**
     * 添加数据
     * @modify wenhui 2017-03-16 创建
     * @param  int   $hotelId   客栈id
     * @param  string   $name   预订人名称
     * @param  string   $mobile   电话
     * @param  array   $startdate   预定时间 || 退房时间
     * @param  int   $night   晚数
     * @param  int   $orderRoomId   子订单id
     * @param  string   $roomType   房型名称
     * @param  string   $roomName   房间名称
     * @param  int   $room  房间id
     * @param  int   $orderInfoId  父订单id
     * @param  int   $areacode  区号
     * @param  int   $hour  小时
     * @param  int   $month  月数
     * @param  int   $type  消息类型 0 = 预定消息 1 = 退房消息
     * @return boolean 执行结果
     */
	public function addPushNewsInfo($hotelId, $name = null, $mobile = null, $startdate = null, $night = null, $orderRoomId = null, $roomType = null, $roomName = null, $room = null, $orderInfoId = null, $areacode = null, $hour = null, $month = null, $type = null) {
		$data = array(
			'hotelentity_id' => $hotelId,
		);

		if (!is_null($name)) {
			$data['name'] = $name;
		}
		if (!is_null($mobile)) {
			$data['mobile'] = $mobile;
		}
		if (!is_null($startdate)) {
			$data['startdate'] = $startdate;
		}
		if (!is_null($night)) {
			$data['night'] = $night;
		}
		if (!is_null($orderRoomId)) {
			$data['orderroom_id'] = $orderRoomId;
		}
		if (!is_null($roomType)) {
			$data['roomtype'] = $roomType;
		}
		if (!is_null($roomName)) {
			$data['roomname'] = $roomName;
		}
		if (!is_null($room)) {
			$data['room'] = $room;
		}
		if (!is_null($orderInfoId)) {
			$data['orderinfo_id'] = $orderInfoId;
		}
        if (!is_null($areacode)) {
            $data['areacode'] = $areacode;
        }
        if (!is_null($hour)) {
            $data['hour'] = $hour;
        }
        if (!is_null($month)) {
            $data['month'] = $month;
        }
        if (!is_null($type)) {
            $data['type'] = $type;
        }

		$newsId = $this->add($data);
		return $newsId ? $newsId : false;
	}

	/**
     * 根据客栈id获取数据
     * @modify wenhui 2017-03-16 创建
     * param  int   $userId     用户id 
     * @return array   $data 数据
     */
	public function getNewsListByUserId($userId = null) {

		if (is_null($userId)) {
			return false;
		}

		return empty($data) ? false : $data;
	}

	/**
     * 根据bk_hotel_newspush.id获取数据
     * @modify wenhui 2017-03-16 创建
     * param  int   $userId     用户id 
     * @return array   $data 数据
     */
	public function getNewsListByNewsId($newsIds) {

		if (is_array($newsIds)) {
			$newsIds = implode(',', $newsIds);
		}

		if (strpos($newsIds, ',') == false) {
			$option['id'] = $newsIds;
		} else {
			$option['id'] = array('in', $newsIds);
		}

		$data = $this->where($option)->select();

		return empty($data) ? false : $data;
	}

	/**
     * 根据客栈id获取数据 
     * @modify wenhui 2017-03-16 创建
     * @param  int   $userId   用户id 
     * @param  int   $hotelId   客栈id 
     * @param  array   $pushList   修改的数据 
     * @return bool    
     */
	public function saveNews($hotelId, $userId, $pushList, $isAdminUsers) {

		$option['adminlogin_id'] = $userId;
		$data = $pushList;

		return $this->where($option)->save($data) ? true : false;
	}

}
